package com.qiantu.phone.ui.adapter;

import static com.qiantu.phone.BuildConfig.OBS_BASE;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bumptech.glide.request.RequestOptions;
import com.qiantu.api.entity.DeviceBean;
import com.qiantu.api.entity.FloorBean;
import com.qiantu.api.entity.RoomBean;
import com.qiantu.api.entity.SceneBean;
import com.qiantu.phone.R;
import com.qiantu.phone.app.AppAdapter;
import com.qiantu.phone.glide.GlideApp;

import java.util.List;

import jp.wasabeef.glide.transformations.RoundedCornersTransformation;

public class RoomGalleryAdapter extends AppAdapter<String> {

    private String selected = "";
    public RoomGalleryAdapter(@NonNull Context context) {
        super(context);
    }

    @NonNull
    @Override
    public RoomGalleryAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new RoomGalleryAdapter.ViewHolder();
    }

    @Override
    public void setData(@Nullable List<String> data) {
        super.setData(data);
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private ImageView roomBackImage;
        private final TextView checkView;
        private ViewHolder() {
            super(R.layout.item_room_gallery);
            roomBackImage = findViewById(R.id.room_backImage);
            checkView = findViewById(R.id.check_view);
        }

        @Override
        public void onBindView(int position) {
            String imageUrl = getItem(position);
            String url = OBS_BASE.substring(0,OBS_BASE.length()-1) + imageUrl;
            GlideApp.with(roomBackImage)
                    .load(url)
                    .apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(50,0, RoundedCornersTransformation.CornerType.ALL)))
                    .into(roomBackImage);
            checkView.setSelected(selected.equals(imageUrl));
        }
    }

    @Override
    public long getItemId(int position) {
        return getData().get(position).hashCode();
    }

    public void setSelected(String selected) {
        this.selected = selected;
        notifyDataSetChanged();
    }
}
